{template '_header'}
<div class="page-heading">

	<span class='pull-right'>
		  {ifp 'sale.coupon.add'}
				 	<a class='btn btn-primary btn-sm' href="{php echo webUrl('sale/coupon/add')}"><i class='fa fa-plus'></i> 添加购物优惠券</a>
					<a class='btn btn-warning btn-sm' href="{php echo webUrl('sale/coupon/add',array('type'=>1))}"><i class='fa fa-plus'></i> 添加充值优惠券</a>
					<a class='btn btn-info btn-sm' href="{php echo webUrl('sale/coupon/add',array('type'=>2))}"><i class='fa fa-plus'></i> 添加收银台优惠券</a>
	   		{/if}
		<a class="btn btn-default  btn-sm" href="{php echo webUrl('sale/coupon')}">返回列表</a>


	</span>
	<h2><i class="fa fa-circle-o"></i>{if !empty($item['id'])}编辑{else}添加{/if}{if $type==0}购物{elseif $type==1}充值{elseif $type==2}收银台{/if}优惠券 <small>{if !empty($item['id'])}修改【{$item['couponname']}】{/if}</small></h2>
</div>

<form {ife 'sale.coupon' $item}action="" method='post'{/if} class='form-horizontal form-validate'>
    <input type="hidden" name="id" value="{$item['id']}">
 <input type="hidden" name="tab" id='tab' value="{$_GPC['tab']}" />


	 <ul class="nav nav-arrow-next nav-tabs" id="myTab">
                    <li {if $_GPC['tab']=='basic' || empty($_GPC['tab'])}class="active"{/if} ><a href="#tab_basic">基本</a></li>
                    <li {if $_GPC['tab']=='center'}class="active"{/if} ><a href="#tab_center">领取设置</a></li>
		 			{if empty($_GPC['type'])}<li {if $_GPC['tab']=='limit'}class="active"{/if} ><a href="#tab_limit">使用限制</a></li>{/if}
					<li {if $_GPC['tab']=='resp'}class="active"{/if} ><a href="#tab_resp">推送</a></li>
					<li {if $_GPC['tab']=='usage'}class="active"{/if} ><a href="#tab_usage">使用说明</a></li>
					<li {if $_GPC['tab']=='code'}class="active"{/if} ><a href="#tab_code">口令玩法</a></li>

                </ul>

                <div class="tab-content">
                    <div class="tab-pane  {if $_GPC['tab']=='basic' || empty($_GPC['tab'])}active{/if}" id="tab_basic">{template 'sale/coupon/post/basic'}</div>
                    <div class="tab-pane  {if $_GPC['tab']=='center'}active{/if}" id="tab_center">{template 'sale/coupon/post/center'}</div>
					{if empty($_GPC['type'])}<div class="tab-pane  {if $_GPC['tab']=='limit'}active{/if}" id="tab_limit">{template 'sale/coupon/post/limit'}</div>{/if}
                    <div class="tab-pane  {if $_GPC['tab']=='resp'}active{/if}" id="tab_resp" >{template 'sale/coupon/post/resp'}</div>
					<div class="tab-pane  {if $_GPC['tab']=='usage'}active{/if}" id="tab_usage" >{template 'sale/coupon/post/usage'}</div>
					<div class="tab-pane  {if $_GPC['tab']=='code'}active{/if}" id="tab_code" >{template 'sale/coupon/post/code'}</div>
            </div>


            <div class="form-group"></div>
            <div class="form-group">
                    <label class="col-sm-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                         {ife 'sale.coupon' $item}
                            <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"  />

                        {/if}
                       <input type="button" name="back" onclick='history.back()' {ife 'sale.coupon' $item}style='margin-left:10px;'{/if} value="返回列表" class="btn btn-default" />
                    </div>
            </div>


</form>
<script language='javascript'>
      require(['bootstrap'],function(){
             $('#myTab a').click(function (e) {
                 e.preventDefault();
                $('#tab').val( $(this).attr('href'));
                 $(this).tab('show');
             })
     });

    function showbacktype(type){

        $('.backtype').hide();
        $('.backtype' + type).show();
    }
	$(function(){

		$('form').submit(function(){

			if($(':input[name=couponname]').isEmpty()){
				Tip.focus($(':input[name=couponname]'),'请输入优惠券名称!');
				return false;
			}
			var backtype = $(':radio[name=backtype]:checked').val();
			if(backtype=='0'){
				if($(':input[name=deduct]').isEmpty()){
					Tip.focus($(':input[name=deduct]'),'请输入立减多少!');
					return false;
				}
			}else if(backtype=='1'){
				if($(':input[name=discount]').isEmpty()){
					Tip.focus($(':input[name=discount]'),'请输入折扣多少!');
					return false;
				}
			}else if(backtype=='2'){
				if($(':input[name=backcredit]').isEmpty() && $(':input[name=backmoney]').isEmpty() && $(':input[name=backredpack]').isEmpty()){
					Tip.focus($(':input[name=backcredit]'),'至少输入一种返利!');
					return false;
				}
			}
			return true;
		})

	})
</script>

{template '_footer'}